package de.acando.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

import com.sun.media.MediaPlayer;

public class Video {
	
	private JPanel panelVideo = new JPanel();
	
	private TitledBorder titleVideo = new TitledBorder("Video");
		
		private JTabbedPane tabpane;
		
		public Video(JTabbedPane tabpane){
			setTabpane(tabpane);
			bestandteileAnordnen();
		}
		
		private void setTabpane(JTabbedPane tabpane){
			this.tabpane = tabpane;		
		}
	
		private void bestandteileAnordnen(){
			panelVideo.setLayout(new BorderLayout());
			Manager.setHint(Manager.PLUGIN_PLAYER, true);
			
		
			try {
				Player mediaPlayer = Manager.createRealizedPlayer(
						new URL("file:/home/riad/workspace/Fig21_06_07/bailey.mpg"));
				
				Component video = mediaPlayer.getVisualComponent();
				Component controls = mediaPlayer.getControlPanelComponent();
				
				if ( video != null ) 
		            panelVideo.add( video, BorderLayout.CENTER ); 

		         if ( controls != null ) 
		            panelVideo.add( controls, BorderLayout.SOUTH ); 
		         
		         mediaPlayer.start(); 
			} catch (NoPlayerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (CannotRealizeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
			
			tabpane.addTab("Video", null, panelVideo, "Zeigt deine geteilten Videos an.");
		}

}
